package com.appspot.autopartymanager.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;

import com.appspot.autopartymanager.model.Event;
import com.google.appengine.api.datastore.Email;

public class Register_eventController extends Controller {
    private static Logger logger = LoggerFactory.getLogger(Register_eventController.class);

    @Override
    public Navigation run() throws Exception {
        HttpServletRequest req = this.request;
        String eventName = req.getParameter("event_name");
        String email = req.getParameter("e_mail");
        logger.info("eventName : " + eventName);
        logger.info("email : " + email);
        
        Event event = new Event();
        event.setName(eventName);
        event.setEmail(new Email(email));
        Datastore.put(event);
        
        logger.info("event created : " + event.getKey().getId());
        
        return redirect("/event?eventid=" + event.getKey().getId());
    }
}
